const { default: Toast } = require("../../vant/toast/toast.js");
var t = require("../common/index.js");
import Dialog from '../../vant/dialog/dialog';

Component({
  properties: {
    data: { type: Object },
    floorIndex: { type: Number },
    isPadding: { type: Number },
  },
  methods: {
    goLink: function (e) {
      console.log('imageList e', e)
      var o = e.currentTarget.dataset, item = o.item, linkType = item.linkType, 
        linkUrl = item.linkUrl, n = item.data, r = o.positionIndex, p = o.timestamp, 
        s = e.currentTarget.offsetTop;
      if (linkType) {
        var m = this.data.floorIndex;
        console.log('isOpen',item.isOpen);
        if(item.isOpen == 0){
          var message = "暂未开放权限, 请联系客服"
          Dialog.confirm({
            title: '温馨提示',
            message,
            showConfirmButton:true,
            confirmButtonText:'联系客服',
          }).then(() => {
            wx.makePhoneCall({
              phoneNumber: '4006860633',
            })
          })
          .catch(() => {
            Dialog.close();
          });
        }else{
          if(linkType == 'product'){
            t.goLink({
              type: "goods",
              data: {
                type: linkType,
                item: item
              },
              saOption: {
                componentName: "imageList",
                floorIndex: m,
                positionIndex: r,
                timestamp: p,
                offsetTop: s
              }
            });
          } else{
            console.log('linkUrl',linkUrl)
            if(linkUrl!=''){
              // wx.navigateTo({
              //   url: linkUrl
              // })
              console.log('item.isSwitchTab',item.isSwitchTab)
              if(item.isSwitchTab == 1){
                wx.switchTab({
                  url: linkUrl
                })
              }else{
                wx.navigateTo({
                  url: linkUrl
                })
              }
            }
          }
        }   
      }
    },
    goTitleLink(e){
      console.log('goTitleLink e',e);
      var item = e.currentTarget.dataset.item;
      var linkUrl = item.titleImgLinkUrl;
      
      console.log('isOpen',item.isOpen);
      if(item.isOpen == 0){
        
      }else{
        if(linkUrl!=''){
          if(item.isSwitchTab == 0){
            wx.navigateTo({
              url: linkUrl
            })
          }else{
            wx.switchTab({
              url: linkUrl
            })
          }
        }
      }
    }
  }
});